﻿using Grow.Domain.Object;

namespace Grow.Domain.Repository
{
    /// <summary>
    /// 仓储
    /// </summary>
    /// <typeparam name="TAggregateRoot"></typeparam>
    public interface IDomainRepository<TAggregateRoot>
        where TAggregateRoot : class, IAggregateRoot
    {
        /// <summary>
        /// 获取未跟踪查询对象
        /// </summary>
        IQueryable<TAggregateRoot> GetQueryableAsNoTracking();

        /// <summary>
        /// 获取查询对象
        /// </summary>
        IQueryable<TAggregateRoot> GetQueryable();

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="aggregateRoot"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task AddAsync(TAggregateRoot aggregateRoot, CancellationToken cancellationToken = default);

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="aggregateRoot"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task UpdateAsync(TAggregateRoot aggregateRoot, CancellationToken cancellationToken = default);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="aggregateRoot"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task RemoveAsync(TAggregateRoot aggregateRoot, CancellationToken cancellationToken = default);


        Task<TAggregateRoot?> FirstOrDefaultAsync(Func<TAggregateRoot, bool> whereFunc, CancellationToken cancellationToken);


        Task<List<TAggregateRoot>> ToListAsync(Func<TAggregateRoot, bool> whereFunc, CancellationToken cancellationToken);

        Task<List<TAggregateRoot>> ToListAsync(Func<TAggregateRoot, bool> whereFunc, int maxCount, CancellationToken cancellationToken);

    }
}
